package net.zdsoft.wpchat.support.client;

import java.util.HashSet;
import java.util.Set;

import net.zdsoft.wpchat.support.entity.Operator;
import net.zdsoft.wpchat.support.entity.UserConfig;

/**
 * 后台登录用户信息
 *
 * @author xuan
 */
public class MemoryUser {
    public static final String KEY = MemoryUser.class.getName();
    public static final String LOGINKEY = "LoginUser";// 前台用户的登陆session

    private String id;
    private String username;
    private String realName;
    private String regionRule;// 用户所在地区
    private final Set<String> regionRules = new HashSet<String>();// 如果为空，默认没有地区权限
    private Set<Integer> authCooperatorIdSet = new HashSet<Integer>();
    // 用户权限配置
    private UserConfig userConfig = null;
    private String upperRegionOfRegionRules;// 得到所有有权限的地区的上级地区,如果regionRules为空，则设为全国
    private int type;

    public MemoryUser() {

    }

    public MemoryUser(Operator userInfo) {
        id = userInfo.getId();
        username = userInfo.getLoginName();
        realName = userInfo.getName();
        regionRule = userInfo.getRegionRule();

        // 得到所有有权限地区的直接上级地区，用作地图打开时限制(好像没必要，如果全线设成All呢?有待观察)
        if (regionRules.isEmpty()) {
            upperRegionOfRegionRules = "";
        }
        type = userInfo.getType();
    }

    /**
     * 判断用户是否拥有该地区的权限
     *
     * @param regionId
     * @return
     */
    public boolean hasPermissionOfRegion(String regionId) {
        return false;
    }

    public Set<String> getRegionRules() {
        return regionRules;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getRealName() {
        return realName;
    }

    public void setRealName(String realName) {
        this.realName = realName;
    }

    public UserConfig getUserConfig() {
        return userConfig;
    }

    public void setUserConfig(UserConfig userConfig) {
        this.userConfig = userConfig;
    }

    public Set<Integer> getAuthCooperatorIdSet() {
        return authCooperatorIdSet;
    }

    public void setAuthCooperatorIdSet(Set<Integer> authCooperatorIdSet) {
        this.authCooperatorIdSet = authCooperatorIdSet;
    }

    public void setUpperRegionOfRegionRules(String upperRegionOfRegionRules) {
        this.upperRegionOfRegionRules = upperRegionOfRegionRules;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    /**
     * 得到所有有权限的地区（regionRules）的上级地区,如果regionRules为空，则设为全国
     *
     * @return
     */
    public String getUpperRegionOfRegionRules() {
        return upperRegionOfRegionRules;
    }

    public void setRegionRule(String regionRule) {
        this.regionRule = regionRule;
    }

    public String getRegionRule() {
        return regionRule;
    }

}
